package com.aishua.fire.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aishua.fire.common.IdUtil;
import com.aishua.fire.entity.statutestudy.AddStatuteStudyInfo;
import com.aishua.fire.entity.statutestudy.StatuteStudyList;
import com.aishua.fire.mapper.StatuteStudyMapper;
import com.aishua.fire.service.StatuteStudyService;
import com.github.pagehelper.PageHelper;

@Service
public class StatuteStudyServiceImpl implements StatuteStudyService 
{
	
	@Autowired
	private StatuteStudyMapper studyMapper;
	
	@Autowired
	private IdUtil idutil;
	
	/**
	 * 应急法规学习_新增应急法规学习目录信息
	 * @param info
	 */
	@Transactional
	public boolean save(AddStatuteStudyInfo info) 
	{
		boolean flag = true;
		List<String> s_name = studyMapper.findByTitle(info.getTitle());
		if (s_name.size() > 0) 
		{
			//代表该部门名称已经存在,无法继续添加
			return false;
		}
		info.setId(idutil.getAllId());
		//添加账户表
		studyMapper.saveStatuteStudyInfo(info);
		return flag;
	}
	
	/**
	 * 应急法规学习_查询应急法规学习列表
	 * @param s_id
	 * @param title
	 * @return
	 */
	@Override
	public List<StatuteStudyList> list(String s_id, String title, int pageNumber, int pageSize)
	{
		PageHelper.startPage(pageNumber, pageSize);
		Map<String, String> param = new HashMap<String, String>();
		param.put("s_id", s_id);
		param.put("title", title);
		
		List<StatuteStudyList> list = studyMapper.statuteStudyList(param);
		return list;
	}

	/**
	 * 应急法规学习_查询应急法规学习列表数量
	 * @param s_id
	 * @param title
	 * @return
	 */
	@Override
	public int listTotal(String s_id, String title)
	{
		Map<String, String> param = new HashMap<String, String>();
		param.put("s_id", s_id);
		param.put("title", title);
		return studyMapper.listTotal(param);
	}
	
	/**
	 * 应急法规学习_修改应急法规学习列表数量
	 */
	@Override
	public boolean update(AddStatuteStudyInfo info) 
	{
		List<String> s_name = studyMapper.findByTitle(info.getTitle());
		if (s_name.size() > 1) 
		{
			//代表该名称已经存在,无法继续修改
			return false;
		}
		studyMapper.updateInfo(info);
		
		return true;
	}

	/**
	 * 应急法规学习_删除应急法规学习列表数量
	 */
	@Override
	public void delete(String id) 
	{
		//删除当前节点
		studyMapper.deleteStatuteStudy(id);
	}

	/**
	 * APP_查询应急法规详情
	 */
	@Override
	public StatuteStudyList getStudyDetail(String s_id) 
	{
		return studyMapper.getStudyDetail(s_id);
	}

}
